package com.zbkj.service.service.impl.splittingAccount;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.common.model.shop.AdAgentApplication;
import com.zbkj.common.model.shop.InvitationCodeEntity;
import com.zbkj.service.dao.shop.AdAgentApplicationDao;
import com.zbkj.service.service.AdAgentApplicationService;
import com.zbkj.service.service.InvitationCodeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RequiredArgsConstructor
public class AdAgentApplicationServiceImpl extends ServiceImpl<AdAgentApplicationDao, AdAgentApplication>
        implements AdAgentApplicationService {
    @Autowired
    InvitationCodeService invitationCodeService;
    @Override
    @DS("pointarchive")
    public AdAgentApplication get(String invitationCode) {
        InvitationCodeEntity invitationCodeEntity = new InvitationCodeEntity();
        invitationCodeEntity.setAgentInvitationCode(invitationCode);
        InvitationCodeEntity code = invitationCodeService.getDevelopAdApply(invitationCodeEntity);
        if (code == null) {
            return null;
        }
        return this.getOne(new QueryWrapper<AdAgentApplication>()
                .lambda()
                .eq(AdAgentApplication::getUserId, code.getUserId())
                .eq(AdAgentApplication::getReviewStatus, "2")
                .last(" limit 1")



        );
    }
    @Override
    @DS("pointarchive")
    public AdAgentApplication getId(String id) {
        return this.getOne(new QueryWrapper<AdAgentApplication>()
                .lambda()
                .eq(AdAgentApplication::getUserId, id)
                .eq(AdAgentApplication::getReviewStatus, "2")
                .last(" limit 1")

        );
    }
}
